package com.ffyc.cms.controller;

import com.ffyc.cms.common.CommonResult;
import com.ffyc.cms.model.Comment;
import com.ffyc.cms.service.CommentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 评论控制层
 */
@RestController
@RequestMapping(path = "comment")
public class CommentController {
    @Autowired
    CommentService commentService;

    /**
     * 查找评论列表
     * @param id
     * @param state
     * @return
     */
    @RequestMapping(path = "getcommentlist")
    public CommonResult getcommentlist(Integer state){
        CommonResult commonResult;
        try{
            List<Comment> commentList = commentService.getcommentlist(state);
            commonResult = new CommonResult(200,"查找成功",commentList);
        }catch (Exception e){
            e.printStackTrace();
            commonResult = new CommonResult(500,"服务器忙，请稍后重试",null);
            return commonResult;
        }
        return commonResult;
    }
    @RequestMapping(path = "getcommentById")
    public CommonResult getcommentById(Integer id){
        CommonResult commonResult;
        try{
            Comment comment = commentService.getcommentById(id);
            commonResult = new CommonResult(200,"查找成功",comment);
        }catch (Exception e){
            e.printStackTrace();
            commonResult = new CommonResult(500,"服务器忙，请稍后重试",null);
            return commonResult;
        }
        return commonResult;
    }

    /**
     * 修改评论状态
     * @param id
     * @param state
     * @return
     */
    @RequestMapping(path = "topass")
    public CommonResult topass(Integer id,Integer state){
        CommonResult commonResult;
        try{
            commentService.topass(id,state);
            commonResult = new CommonResult(200,"修改状态成功",null);
        }catch (Exception e){
            e.printStackTrace();
            commonResult = new CommonResult(500,"服务器忙，请稍后重试",null);
            return commonResult;
        }
        return commonResult;
    }

}